<template>
    <van-nav-bar
        title="新增地址"
        left-arrow
        @click-left="router.go(-1)"
        />
    <van-address-edit
        :area-list="areaList"
        :show-delete="false"
        show-set-default
        show-search-result
        :area-columns-placeholder="['请选择', '请选择', '请选择']"
        @save="onSave"
    />
</template>。
<script lang="ts" setup>
import { useRouter } from "vue-router";
import { areaList } from '@vant/area-data';
import { ref, Ref } from "vue";
import { useCommonStore } from "../../../store";
import { addAddressApi } from "../../../apis/addressApis";
import { showToast } from "vant";

const router = useRouter()
const uid:string = useCommonStore().userInfo.id

// 新增地址接口
interface AddressInf{
    addressDetail: string,
    areaCode: string,
    city: string,
    country: string,
    county: string,
    isDefault: boolean,
    name: string,
    province: string,
    tel: string
}


async function onSave(info:AddressInf){
    const addList:Ref= ref({
        userId: uid,
        name: '',
        phone: '',
        address: '',
        tag: '',
    })
    addList.value.tag = info.isDefault.toString()
    addList.value.name = info.name
    addList.value.phone = info.tel
    addList.value.address = info.province + info.city + info.county + info.addressDetail
     console.log(addList.value);
    let _res = await addAddressApi(addList.value)
    console.log(_res);
    
    if(_res.code == 200){
        showToast('添加成功！')
    }
}
</script>

<style lang="less" scoped>
@import url('../../../style/comon.less');
::v-deep .van-icon-arrow-left:before{
    color: @g9;
}
::v-deep .van-button--primary{
    background-color: @g7;
    border: none;
}
::v-deep .van-switch--on{
    background: @g7;
}
</style>